console.log('%c准备好消灭营销号了么！！！','color:red;font-size:20px')

/*
* fn:{
*   bilibili:``
* }
* {
*   bilibili:[],
* }
* */


let keyword = []
window.addEventListener("load", function () {
    chrome.storage.sync.get('keywords', (data) => {
        keyword = data.keywords||[]

        // 监听页面load事件
        function check() {
            let checklist = [...document.querySelectorAll('em')]
            checklist.forEach(d => {
                if (keyword.includes(d.innerText)) {
                    d.style.color = 'green'
                }
            })
            requestAnimationFrame(check)
        }
        check()
    });

})


// 监听消息
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
    // console.log('request', request)
    if (request.type === 'update') {
        keyword = request.data
    }
    if (request.type === 'commit') {
        keyword.push(request.data)
    }

    // 将关键词存储到 Chrome 的本地存储中
    chrome.storage.sync.set({ keywords: keyword }, () => {
        alert('关键词更新成功！');
    });

    sendResponse(request.type)
});
